package demo4;

import java.util.Objects;

class Person{

}

class Student{
    public String id;
    public Student(String id){
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                '}';
    }

    /*@Override
    public boolean equals(Object obj) {
        Student tmp = (Student) obj;
        if(tmp.id.equals(this.id)){
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {

    public static void main(String[] args) {
        Student student1 = new Student("1234");
        Student student2 = new Student("1234");

        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());
    }

    public static void main2(String[] args) {
        Student student1 = new Student("1234");
        Student student2 = new Student("1234");

        System.out.println(student1 == student2);

        Person person = new Person();

        System.out.println(student1.equals(student2));

        /*String str1 = new String("1223");
        String str2 = new String("1234");
        // 如果String没有equals这个方法,调用谁的?
        System.out.println(str1.equals(str2));*/


    }
    public static void func(Object obj){
        System.out.println(obj);
    }

    public static void main1(String[] args) {
        func(new Student("1234"));
        func(new Person());
    }
}
